<link rel="stylesheet" type="text/css" href="../stylesheet/style.css"/>
<?php
/*
* @author Nguyen Xuan Hong
* @copyright 2011
*/

require_once('../includes/user.tbl.php');

if($_GET['mode'] == 'listuser')
{
	$pClsUser = new clsUserTable();	
	if($pClsUser->avaibleSubmit()){
		$pClsUser->loadBuffer();
		$pClsUser->insertDB();
		echo acpredirect();
		exit();
	}
	echo $pClsUser->createForm('Thêm học sinh');
	
	require_once('../includes/templates.php');
	$table = new clsTable('lstuser',array(array("ID", "1"),array("Tên học sinh", 0),array("Sửa", 1),array("Xóa", 1)));

	$list_user = $pClsUser->listobj(10);
	foreach($list_user as $user){
		$html_remove =      '<a href="?page=user&mode=deleteuser&id='.$user->value('id').'">Xóa</a>';
		$html_edit = 	'<a href="?page=user&mode=edituser&id='.$user->value('id').'">Sửa</a>';	
		$table->addRow($user->value('id'),array($user->value('id'),$user->value('name'), $html_edit,$html_remove));
	}
	echo $table->putHTML(true);
	exit();
}

if($_GET['mode'] == 'deleteuser'){		
	// Redefine insert
	$deleteid = sget('id');			
	$pClsUser = new clsUserTable($deleteid);
	if(!$_POST['submit']){
		?>
        
	<center><div class="notification warning">
        <span></span>
        <p><strong>Warning!</strong> 
		<div class="text">Bạn có muốn xóa thông tin học sinh này không</div> 
            <div class="btn"><form method='post'><input type='submit' name='submit' value = 'Xóa' /></form></div>
         </p>
	</div></center>
        <?
		exit();
	}
	$pClsUser->removeDB('id', $deleteid);
       header("location:index.php?page=user&mode=listuser");
	exit();
}

if($_GET['mode'] == 'edituser')
{
	$edit = (int)sget('id');
	$pClsUser = new clsUserTable($deleteid);
	if($pClsUser->avaibleSubmit()){
		$pClsUser->loadBuffer();
		$pClsUser->updateDB('id',$edit);
        echo acpredirect('page=user&mode=listuser');
		exit();
	}
	$pClsUser->loadDB('id',$edit);
       echo $pClsUser->createForm('Sửa thông tin học sinh');
	exit();
}
?> 
